//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Xml;
using CommunityServer.Configuration;

namespace CommunityServer.Components
{
	/// <summary>
	/// Summary description for ReferralsJob.
	/// </summary>
	public class PostAttachmentCleanupJob : IJob
	{
		public PostAttachmentCleanupJob()
		{
		}

		public void Execute(XmlNode node)
		{
			XmlAttribute expiresAfterHoursNode = node.Attributes["expiresAfterHours"];
			int expiresAfterHours = 2;

			if(expiresAfterHoursNode != null)
			{
				try { expiresAfterHours = int.Parse(expiresAfterHoursNode.Value); }
				catch { expiresAfterHours = 2; }
			}

			CommonDataProvider dp = CommonDataProvider.Instance();
			dp.ExpireTemporaryPostAttachments(DateTime.Now.AddHours(-expiresAfterHours));
		}
	}
}

